<!doctype html>
<html class="no-js" lang="zh-cn">

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <meta property="og:title" content="">
    <meta property="og:type" content="">
    <meta property="og:url" content="">
    <meta property="og:image" content="">

    <link rel="manifest" href="site.webmanifest">
    <link rel="apple-touch-icon" href="icon.png">
    <!-- Place favicon.ico in the root directory -->

    <link rel="stylesheet" href="css/normalize.css">
    <link rel="stylesheet" href="css/main.css">

    <link href="https://fonts.font.im/css?family=Roboto:300" rel="stylesheet">
    <link href="https://fonts.font.im/css?family=Source+Code+Pro" rel="stylesheet">
    <link rel="stylesheet" href="https://unpkg.com/@highlightjs/cdn-assets@11.0.1/styles/default.min.css">
    <script src="https://unpkg.com/@highlightjs/cdn-assets@11.0.1/highlight.min.js"></script>


    <meta name="theme-color" content="#fafafa">

    <script src="https://unpkg.com/vue@next"></script>
</head>

<body>

    <!-- Add your site or application content here -->
    <header>
        <nav>
            <ul id="header-nav">
                <li><a href="#">CimManagedTemplate</a></li>
                <li v-for="menu in menus">
                    <a v-bind:href="menu.url" class="list-item">{{menu.name}}</a>
                </li>
            </ul>
        </nav>
    </header>

    <div class="sticky"></div>

    <main>
        <aside class="left">
            <h2>How Tos</h2>
            <ul id="create-nav" class="nav">
                <li>
                    <h3>创建</h3>
                </li>
                <hr>
                <li v-for="anchor in anchors" v-bind:class="{active: file == anchor.url}">
                    <a :href="anchor.url">{{anchor.name}}</a>
                </li>
            </ul>
            <ul id="serialize-nav" class="nav">
                <li>
                    <h3>序列与反序列化</h3>
                </li>
                <hr>
                <li><a href="#">导入</a></li>
                <li><a href="#">导出</a></li>
            </ul>
        </aside>
        <article>
            <section class="overview">
                <h1>创建矩形</h1>
                <h2>创建一个无参矩形模板
                </h2>
                <p>
                    本示例演示如何使用模板的基础接口来创建一个无参矩形。
                </p>
                <hr>
            </section>
            <section class="content">
                <h2 id="keyin" class="anchor"><a href="#keyin">命令</a></h2>
                <pre><code class="language-xml">CimManagedTemplate Create Rectangle</code></pre>
            </section>

            <section class="content">
                <h2 id="language" class="anchor"><a href="#language">编程语言</a></h2>
                <pre><code class="language-plaintext">C#</code></pre>
            </section>

            <section class="content">
                <h2 id="create-template" class="anchor"><a href="#create-template">创建模板对象</a></h2>
                <p>首先，我们需要创建一个模板对象，用它来保存模板数据。这些数据包括几何数据，几何构件的连接信息，约束关系，参数信息等等。</p>
                <pre><code class="language-cs">
BCT.Template template = new BCT.Template("Rectangle");
                </code></pre>
            </section>

            <section class="content">
                <h2 id="create-component" class="anchor"><a href="#create-component">创建几何组件</a></h2>
                <p>接下来，我们需要创建一个几何组件，用它来保存该几何图形的基本信息。</p>
            <pre><code class="language-cs">
var component = template.AddComponent();
                </code></pre>
            </section>

            <section class="content">
                <h2 id="create-points" class="anchor"><a href="#create-points">创建点数据</a></h2>
                <p>然后，我们需要创建一些点，用它来保存该几何组件的连接点信息。 如果是无参模板，点上只需存储坐标信息即可；如果是参数化模板，则根据需要追加约束等其他信息。</p>
            <pre><code class="language-cs">
var P0 = template.AddPoint(-halfLength + Origin.X, -halfWidth + Origin.Y, false);
var P1 = template.AddPoint(-halfLength + Origin.X, halfWidth + Origin.Y, false);
var P2 = template.AddPoint(halfLength + Origin.X, halfWidth + Origin.Y, false);
var P3 = template.AddPoint(halfLength + Origin.X, -halfWidth + Origin.Y, false);
                </code></pre>
            </section>

            <section class="content">
                <h2 id="create-connection" class="anchor"><a href="#create-connection">添加拓扑关系</a></h2>
                <p>之后，我们需要将创建的点按照顺序连接起来，这样他就能够表达一个闭合的图形了。</p>
            <pre><code class="language-cs">
component.AddLine(P0.Name, P1.Name);
component.AddLine(P1.Name, P2.Name);
component.AddLine(P2.Name, P3.Name);
component.AddLine(P3.Name, P0.Name);
                </code></pre>
            </section>

            <section class="content">
                <h2 id="add-to-model" class="anchor"><a href="#add-to-model">添加到模型</a></h2>
                <p>最后，我们将模板转换成几何曲线，然后添加到模型中。这就是一个模板的基本使用流程。</p>
            <pre><code class="language-cs">
BG.CurveVector curves = template.ToCurveVector();

BD.Elements.Element element = BD.Elements.DraftingElementSchema.ToElement(BM.Session.Instance.GetActiveDgnModel(), curves, null);
element.AddToModel();
                </code></pre>
            </section>

        </article>
        <aside class="right">
            <nav>
                <ul id="right-nav" class="nav">
                    <li>
                        <h4>当前页</h4>
                    </li>
                    <hr>
                    <li v-for="anchor in anchors" v-bind:class="{active: activeAnchor == anchor.url}">
                        <a v-bind:href="anchor.url" @click="activeChanged(anchor)">{{anchor.name}}</a>
                    </li>
                </ul>
            </nav>
        </aside>
    </main>

    <script src="js/vendor/modernizr-3.11.2.min.js"></script>
    <script src="js/plugins.js"></script>
    <script src="js/main.js"></script>

    <script>
        const HeaderNav = {
            data() {
                return {
                    activeAnchor: '',
                    menus: [
                        { url: '', name: '首页' },
                        { url: '', name: '文档' },
                        { url: 'https://communities.bentley.com/', name: '社区' },
                        { url: 'https://openroads.com.cn/', name: '关于' },
                        { url: '', name: 'FAQ' },
                    ]
                }
            },
        }

        const CreateNav = {
            data() {
                return {
                    activeAnchor: '',
                    anchors: [
                        { url: 'create_rectangle.html', name: '矩形' },
                        { url: 'create_through_hole.html', name: '镂空矩形' },
                        { url: 'create_parametric_through_hole.html', name: '参数化模板' },
                    ],
                    file: location.href.substr(location.href.lastIndexOf('/') + 1),
                }
            },
        }

        const RightNav = {
            data() {
                return {
                    activeAnchor: '',
                    anchors: [
                        { url: '#keyin', name: '命令' },
                        { url: '#language', name: '编程语言' },
                        { url: '#create-template', name: '创建模板对象' },
                        { url: '#create-component', name: '创建模板组件' },
                        { url: '#create-points', name: '创建点数据' },
                        { url: '#create-connection', name: '添加拓扑关系' },
                        { url: '#add-to-model', name: '添加到模型' },
                    ]
                }
            },
            methods: {
                activeChanged(anchor) {
                    this.activeAnchor = anchor.url;
                }
            }
        }

        Vue.createApp(HeaderNav).mount('#header-nav');
        Vue.createApp(CreateNav).mount('#create-nav');
        Vue.createApp(RightNav).mount('#right-nav');
    </script>

    <script>hljs.highlightAll();</script>

    <!-- Google Analytics: change UA-XXXXX-Y to be your site's ID. -->
    <script>
        window.ga = function () { ga.q.push(arguments) }; ga.q = []; ga.l = +new Date;
        ga('create', 'UA-XXXXX-Y', 'auto'); ga('set', 'anonymizeIp', true); ga('set', 'transport', 'beacon'); ga('send', 'pageview')
    </script>
    <script src="https://www.google-analytics.com/analytics.js" async></script>
</body>

</html>